﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Forward.aspx.cs" Inherits="BEGDC.CC.Web.Workflow.Dialog.Forward" %>

<%@ Register TagPrefix="cc1" Namespace="BEGDC.CC.Web.Control" Assembly="ASBCC.Web" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Forward</title>
    <link href="../../css/global.css" type="text/css" rel="stylesheet" />
    <link href="../../css/style.css" type="text/css" rel="stylesheet" />

    <script language="javascript" type="text/javascript">

        var sourceActionButton_Forward;
        var sourceActionButton_ForwardBack;
        var selectedUserIdArr;

        function validateExecute() {
            var tmp = document.getElementById("SearchStaff_Employee_Flow_ID").value;
            document.getElementById("hidForwardTargetUserID").value = tmp;
            if (tmp == "" || tmp == "0") {
                alert(document.getElementById("hidForwardTargetRequired").value);
                return false;
            }
            var comment = document.getElementById("txtComments").value;
            if (comment == null || comment == "") {
                alert(document.getElementById("hidCommentRequired").value);
                return false;
            }
            return true;
        }

        function executeForward() {
            if (!validateExecute()) return;
            if (opener && opener.__wf_doActionPostBack) {
                var comment = document.getElementById("txtComments").value;
                var auditDestination = getAuditDestination();
                if (auditDestination == null) {
                    alert(document.getElementById("hidAskForMoreTargetRequired").value);
                    return;
                }
                opener.__wf_doActionPostBack(sourceActionButton_Forward, auditDestination, comment);
                window.close();
            }
        }

        function executeForwardBack() {
            if (!validateExecute()) return;
            if (opener && opener.__wf_doActionPostBack) {
                var comment = document.getElementById("txtComments").value;
                var auditDestination = getAuditDestination();
                if (auditDestination == null) {
                    alert(document.getElementById("hidAskForMoreTargetRequired").value);
                    return;
                }
                opener.__wf_doActionPostBack(sourceActionButton_ForwardBack, auditDestination, comment);
                window.close();
            }
        }

        window.onload = function() {
            sourceActionButton_Forward = opener.__wf_sourceActionButton;
            sourceActionButton_ForwardBack = opener.document.getElementById(sourceActionButton_Forward.id + "Back");
        }

        function OpenSelector() {
            vela3OpenSelectSingleUserDialog('../../../',
	                    'hidForwardTargetUserID',
	                    '',
	                    'txtForwardTargetUserNameEn',
	                    '',
	                    '');
        }

        function onSelectUsersCallback(selectedUsers) {
            selectedUserIdArr = null;

            var txtForwardTargetUserNameEn = document.getElementById("txtForwardTargetUserNameEn");
            txtForwardTargetUserNameEn.value = "";

            if (selectedUsers == null || selectedUsers.length == 0) return;

            var userIdArr = new Array();
            var userNameEnArr = new Array();

            for (var i = 0; i < selectedUsers.length; i++) {
                var selectedUser = selectedUsers[i];
                userIdArr[i] = selectedUser.UserId;
                userNameEnArr[i] = selectedUser.UserNameEn;
            }

            selectedUserIdArr = userIdArr;
            txtForwardTargetUserNameEn.value = userNameEnArr.join(",");
        }

        function getAuditDestination() {
            var SEPARATOR_USER = ';';
            var SEPARATOR_ACTIVITY_DESTINATION = '|';
            var SEPARATOR_AUDIT_DESTINATION = '$';

            var activityName = document.getElementById("hidActivityName").value;
            var user = document.getElementById("hidForwardTargetUserID").value;
            return activityName + SEPARATOR_ACTIVITY_DESTINATION + user;
        }
    </script>

</head>
<body style="background: none;">
    <h3 class="ev-header-section">
        &nbsp;FORWARD</h3>
    <form id="form1" runat="server">
    <table width="100%">
        <tr class="ev-row2">
            <td class="title" width="18%">
                <span class="Star">*</span>Select Target User ：<br />
                选择目标用户&nbsp;&nbsp;
            </td>
            <td class="val">
                <asp:HiddenField ID="hidForwardTargetUserID" runat="server"></asp:HiddenField>
                <cc1:UserSearchControl ID="SearchStaff" runat="server" Width="90%"></cc1:UserSearchControl>
            </td>
        </tr>
        <tr class="ev-row2">
            <td class="title">
                <span class="Star">*</span>Your Comments ：<br />
                您的审批意见&nbsp;&nbsp;
            </td>
            <td class="val">
                <asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" Width="90%" Height="120px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="padding5 ac">
                <br />
                <asp:Button runat="server" ID="btnForward" Text="<%$ Resources:Workflow, Forward%>" CssClass="btn" OnClientClick="executeForward(); return"
                    UseSubmitBehavior="false" />&nbsp;
                <asp:Button runat="server" ID="btnForwardBack" Text="<%$ Resources:Workflow, ForwardBack%>" CssClass="btn" OnClientClick="executeForwardBack(); return"
                    UseSubmitBehavior="false" Visible="false" />&nbsp;
                <asp:Button runat="server" ID="btnCancel" Text="<%$ Resources:Workflow, Cancel%>" CssClass="btn" OnClientClick="window.opener=null;window.close(); return false"
                    UseSubmitBehavior="false" />
            </td>
        </tr>
    </table>
    <asp:HiddenField ID="hidForwardTargetRequired" runat="server" />
    <asp:HiddenField ID="hidCommentRequired" runat="server" />
    <asp:HiddenField ID="hidActivityName" runat="server" />
    </form>
</body>
</html>